package com.yuyue.dronesystem.configs;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yuyue.dronesystem.components.LoginHandlerInterceptor;
import com.yuyue.dronesystem.components.MyLocaleResolver;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * MyMvcConfig
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    // 设置视图映射
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/main").setViewName("main/main");
        // WebMvcConfigurer.super.addViewControllers(registry);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/main/**");
            // .excludePathPatterns("/","/index","/login","/user/login","/favicon.ico",
            //                      "/views/**", "/res/**","/asserts/**","/webjars/**","/druid/**","/actuator/**");
    }

    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }
    
}